<?php 	
	header('Access-Control-Allow-Origin: *');
	header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
	header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE');
	include('connect.php');

	$m = $_GET['m'];
	$sql='';

	if($m == 'getkeys'){
		$type = $_GET['type'];
		$sql = 'select tag from tag where type ='.$type;
	}else{
		if(!empty($_GET['tag'])){
			$tag = $_GET['tag'];
			// $sql = "select tag from tag where tag like '".$tag."%'";
			$sql = 'select tag from tag where tag like "'.$tag.'%"';
		}else{
			$sql = 'select tag from tag';
		}
	}

	
	$result = $db->query($sql);

	$rows = [];
	$values = [];
	if($result->num_rows > 0){
		while($row = $result->fetch_array(MYSQLI_ASSOC)){
			$rows[] = $row;
		}
	}

	foreach($rows as $value){
		array_push($values, $value['tag']);
	}

	echo json_encode($values);
	
	



